package boot

import (
	model "beesoft.ink/application/text/app/model/base"
	service "beesoft.ink/application/text/app/service/base"
	"beesoft.ink/application/text/router"
	"github.com/labstack/echo/v4"
	"github.com/prometheus/client_golang/prometheus"
	"github.com/spf13/viper"
	"time"
)

func Init() {
	service.InitCodePath() // 初始化程序目录
	service.LoadConfig()   // 加载配置

	e := echo.New()

	initSystem(e)
	initPrometheus()

	router.Middleware(e)
	router.Init(e)

	e.Logger.Fatal(e.Start(viper.GetString("server.address")))
}

func initSystem(e *echo.Echo) {
	loc, err := time.LoadLocation("Asia/Shanghai")
	if err != nil {
		e.Logger.Fatal(err)
	}

	time.Local = loc
}
func initPrometheus() {
	prometheus.MustRegister(model.HttpRequestsTotal)
}
